<template>
  <view class="p-4 fixed w-full bottom-0 fixedButton z-50">
    <slot></slot>
  </view>
  <view
    v-if="placeholder"
    :style="`height: ${placeholderHeight}px;backgroundColor: inherit;`"></view>
</template>

<script setup lang="ts">
const props = defineProps({
  /** 是否需要底部占位 */
  placeholder: {
    type: Boolean,
    default: false
  }
})

// 获取盒子总高度
const placeholderHeight = ref(0)
async function getHeight() {
  const ins: any = getCurrentInstance()
  const query = uni.createSelectorQuery().in(ins.proxy)
  await nextTick()
  await nextTick()
  query
    .select('.fixedButton')
    .boundingClientRect((res) => {
      const { height } = res as UniApp.NodeInfo
      placeholderHeight.value = height ?? 0
    })
    .exec()
}

onMounted(() => {
  if (props.placeholder) getHeight()
})
</script>

<style lang="scss" scoped></style>
